using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BerkoRules.Objects;
using BerkoRules.Mappers;
using System.Configuration;
using System.IO;
using Reportes;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using BerkoRules.Entities;

namespace Berko
{
    public partial class frmClientes : Form
    {
        public frmClientes()
        {
            this.direcciones = null;
            this.personas = null;
            this.clientes = null;
            this._indexCliente = 0;
            this._cambio = false;
            this.esModificacion = false;
            this.huboCambios = false;
            this.botonMod = false;
            this.listaArchs = null;
            this.listaArchsN = null;
            this.listaArchsE = null;

            InitializeComponent();
        }
        private bool _cargarTodos = true;
        public bool CargarTodos
        {
            get { return _cargarTodos; }
            set { _cargarTodos = value; }
        }

        private void Agregar_Direccion()
        {
            Clientes_DireccionesObject item = new Clientes_DireccionesObject();
            if (this.direcciones == null)
            {
                this.direcciones = new Clientes_DireccionesObjectList();
            }
            this.direcciones.Add(item);
            this.gvDirecciones.DataSource = null;
            this.gvDirecciones.DataSource = this.direcciones;
        }

        private void Agregar_Persona()
        {
            Clientes_PersonasObject item = new Clientes_PersonasObject();
            if (this.personas == null)
            {
                this.personas = new Clientes_PersonasObjectList();
            }
            this.personas.Add(item);
            this.gvPersonas.DataSource = null;
            this.gvPersonas.DataSource = this.personas;
        }

        private void BindingNavigatorMoveFirstItem_Click(object sender, EventArgs e)
        {
            if (this.huboCambios)
            {
                this.Guardar();
            }
            this._indexCliente = 0;
            this._cambio = true;
            this.chkItalic.Checked = false;
            this.chkNegrita.Checked = false;
            this.chkSubrayado.Checked = false;
            this.chkTachado.Checked = false;
            this.Cargar_Cliente();
        }

        private void BindingNavigatorMoveLastItem_Click(object sender, EventArgs e)
        {
            if (this.huboCambios)
            {
                this.Guardar();
            }
            this._indexCliente = this.clientes.Count - 1;
            this._cambio = true;
            this.chkItalic.Checked = false;
            this.chkNegrita.Checked = false;
            this.chkSubrayado.Checked = false;
            this.chkTachado.Checked = false;
            this.Cargar_Cliente();
        }

        private void BindingNavigatorMoveNextItem_Click(object sender, EventArgs e)
        {
            if (this.huboCambios)
            {
                this.Guardar2();
            }
            this._indexCliente++;
            this._cambio = true;
            this.chkItalic.Checked = false;
            this.chkNegrita.Checked = false;
            this.chkSubrayado.Checked = false;
            this.chkTachado.Checked = false;
            this.Cargar_Cliente();
        }

        private void BindingNavigatorMovePreviousItem_Click(object sender, EventArgs e)
        {
            if (this.huboCambios)
            {
                this.Guardar();
            }
            this._indexCliente--;
            this._cambio = true;
            this.chkItalic.Checked = false;
            this.chkNegrita.Checked = false;
            this.chkSubrayado.Checked = false;
            this.chkTachado.Checked = false;
            this.Cargar_Cliente();
        }

        private void Cargar_Cliente()
        {
            this.tbA.Text = "";
            this.tbB.Text = "";
            this.tbC.Text = "";
            this.tbD.Text = "";
            if (!this.txtEmpresa.ReadOnly)
            {
                this.Habilitar_Pantalla(false);
            }
            this.Verificar_Tiene_Alarmas();
            this.Verificar_Archivos();
            this.Traer_Direcciones(this.clientes[this._indexCliente].cli_ID);
            this.Traer_Personas(this.clientes[this._indexCliente].cli_ID);
            this.txtEmpresa.Text = this.clientes[this._indexCliente].cli_Nombre;
            this.txtActividad.Text = this.clientes[this._indexCliente].cli_Actividad;
            this.txtObs.Text = this.clientes[this._indexCliente].cli_Observacion;
            if (this.clientes[this._indexCliente].cli_Categoria.HasValue)
            {
                this.cboCategorias.SelectedIndex = this.clientes[this._indexCliente].cli_Categoria.Value - 1;
            }
            else
            {
                this.cboCategorias.Text = string.Empty;
            }
            if (!File.Exists(ConfigurationManager.AppSettings["textosCli"] + this.clientes[this._indexCliente].cli_ID.ToString() + ".rtf"))
            {
                try
                {
                    StreamWriter writer = new StreamWriter(ConfigurationManager.AppSettings["textosCli"] + this.clientes[this._indexCliente].cli_ID.ToString() + ".rtf");
                    writer.Write(this.clientes[this._indexCliente].cli_Historial);
                    writer.Close();
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                }
            }
            try
            {
                this.txtHistorial.LoadFile(System.Configuration.ConfigurationManager.AppSettings["textosCli"] + this.clientes[this._indexCliente].cli_ID.ToString() + ".rtf", RichTextBoxStreamType.RichText);
            }
            catch (Exception exception3)
            {
                Exception exception2 = exception3;
                this.txtHistorial.SelectionFont = this.txtContacto1.Font;
                this.txtHistorial.SelectionColor = Color.Black;
                this.txtHistorial.Font = this.txtContacto1.Font;
                this.txtHistorial.Text = this.clientes[this._indexCliente].cli_Historial;
            }
            this.txtEmail.Text = this.clientes[this._indexCliente].cli_Email;
            this.txtSitio.Text = this.clientes[this._indexCliente].cli_SitioWeb;
            this.txtCuitA.Text = this.clientes[this._indexCliente].cli_Cuit;
            this.txtFiscalA.Text = this.clientes[this._indexCliente].cli_Fiscal;
            this.txtDirFiscalA.Text = this.clientes[this._indexCliente].cli_DirFiscal;
            this.txtLocaFiscalA.Text = this.clientes[this._indexCliente].cli_LocalidadFiscal;
            if (this.clientes[this._indexCliente].cli_SitFiscal.HasValue)
            {
                this.cboFiscalA.SelectedIndex = this.clientes[this._indexCliente].cli_SitFiscal.Value - 1;
            }
            else
            {
                this.cboFiscalA.Text = string.Empty;
                this.cboFiscalA.SelectedValue = -1;
            }
            if (this.clientes[this._indexCliente].fac_ID.HasValue)
            {
                this.cboFacturarA.SelectedValue = this.clientes[this._indexCliente].fac_ID.Value;
            }
            else
            {
                this.cboFacturarA.Text = string.Empty;
                this.cboFacturarA.SelectedValue = -1;
            }
            if (this.txtFiscalA.Text.Trim() != string.Empty)
            {
                this.tbA.Text = "1";
            }
            if (this.txtDirFiscalA.Text.Trim() != string.Empty)
            {
                this.tbA.Text = "1";
            }
            if (this.txtLocaFiscalA.Text.Trim() != string.Empty)
            {
                this.tbA.Text = "1";
            }
            if (this.cboFiscalA.SelectedValue != null)
            {
                this.tbA.Text = "1";
            }
            this.txtCuitB.Text = this.clientes[this._indexCliente].cli_CuitB;
            this.txtFiscalB.Text = this.clientes[this._indexCliente].cli_FiscalB;
            this.txtDirFiscalB.Text = this.clientes[this._indexCliente].cli_DirFiscalB;
            this.txtLocaFiscalB.Text = this.clientes[this._indexCliente].cli_LocalidadFiscalB;
            if (this.clientes[this._indexCliente].cli_SitFiscalB.HasValue)
            {
                this.cboFiscalB.SelectedIndex = this.clientes[this._indexCliente].cli_SitFiscalB.Value - 1;
            }
            else
            {
                this.cboFiscalB.Text = string.Empty;
                this.cboFiscalB.SelectedValue = -1;
            }
            if (this.clientes[this._indexCliente].fac_IDB.HasValue)
            {
                this.cboFacturarB.SelectedValue = this.clientes[this._indexCliente].fac_IDB.Value;
            }
            else
            {
                this.cboFacturarB.Text = string.Empty;
                this.cboFacturarB.SelectedValue = -1;
            }
            if (this.txtFiscalB.Text.Trim() != string.Empty)
            {
                this.tbB.Text = "2";
            }
            if (this.txtDirFiscalB.Text.Trim() != string.Empty)
            {
                this.tbB.Text = "2";
            }
            if (this.txtLocaFiscalB.Text.Trim() != string.Empty)
            {
                this.tbB.Text = "2";
            }
            if (this.cboFiscalB.SelectedValue != null)
            {
                this.tbB.Text = "2";
            }
            this.txtCuitC.Text = this.clientes[this._indexCliente].cli_CuitC;
            this.txtFiscalC.Text = this.clientes[this._indexCliente].cli_FiscalC;
            this.txtDirFiscalC.Text = this.clientes[this._indexCliente].cli_DirFiscalC;
            this.txtLocaFiscalC.Text = this.clientes[this._indexCliente].cli_LocalidadFiscalC;
            if (this.clientes[this._indexCliente].cli_SitFiscalC.HasValue)
            {
                this.cboFiscalC.SelectedIndex = this.clientes[this._indexCliente].cli_SitFiscalC.Value - 1;
            }
            else
            {
                this.cboFiscalC.Text = string.Empty;
                this.cboFiscalC.SelectedValue = -1;
            }
            if (this.clientes[this._indexCliente].fac_IDC.HasValue)
            {
                this.cboFacturarC.SelectedValue = this.clientes[this._indexCliente].fac_IDC.Value;
            }
            else
            {
                this.cboFacturarC.Text = string.Empty;
                this.cboFacturarC.SelectedValue = -1;
            }
            if (this.txtFiscalC.Text.Trim() != string.Empty)
            {
                this.tbC.Text = "3";
            }
            if (this.txtDirFiscalC.Text.Trim() != string.Empty)
            {
                this.tbC.Text = "3";
            }
            if (this.txtLocaFiscalC.Text.Trim() != string.Empty)
            {
                this.tbC.Text = "3";
            }
            if (this.cboFiscalC.SelectedValue != null)
            {
                this.tbC.Text = "3";
            }
            this.txtCuitD.Text = this.clientes[this._indexCliente].cli_CuitD;
            this.txtFiscalD.Text = this.clientes[this._indexCliente].cli_FiscalD;
            this.txtDirFiscalD.Text = this.clientes[this._indexCliente].cli_DirFiscalD;
            this.txtLocaFiscalD.Text = this.clientes[this._indexCliente].cli_LocalidadFiscalD;
            this.chkSeguir.Checked = (bool)(this.clientes[this._indexCliente].cli_Seguir == null) ? false : true;
            if (this.clientes[this._indexCliente].cli_SitFiscalD.HasValue)
            {
                this.cboFiscalD.SelectedIndex = this.clientes[this._indexCliente].cli_SitFiscalD.Value - 1;
            }
            else
            {
                this.cboFiscalD.Text = string.Empty;
                this.cboFiscalD.SelectedValue = -1;
            }
            if (this.clientes[this._indexCliente].fac_IDD.HasValue)
            {
                this.cboFacturarD.SelectedValue = this.clientes[this._indexCliente].fac_IDD.Value;
            }
            else
            {
                this.cboFacturarD.Text = string.Empty;
                this.cboFacturarD.SelectedValue = -1;
            }
            if (this.txtFiscalD.Text.Trim() != string.Empty)
            {
                this.tbD.Text = "4";
            }
            if (this.txtDirFiscalD.Text.Trim() != string.Empty)
            {
                this.tbD.Text = "4";
            }
            if (this.txtLocaFiscalD.Text.Trim() != string.Empty)
            {
                this.tbD.Text = "4";
            }
            if (this.cboFiscalD.SelectedValue != null)
            {
                this.tbD.Text = "4";
            }
            this.Cargar_Unidades();
        }

        private void Cargar_Unidades()
        {
            rpt_Unidades_Por_Cliente cliente = new rpt_Unidades_Por_Cliente();
            DataSet set = new DataSet();
            DataTable table = new DataTable("dt_Unidades");
            try
            {
                table = UnidadesMapper.Instance().RPT_Por_Cliente(this.clientes[this._indexCliente].cli_ID, "").Copy();
                if (table != null)
                {
                    int num2 = table.Rows.Count - 1;
                    for (int i = 0; i <= num2; i++)
                    {
                        table.Rows[i][6] = i + 1;
                    }
                }
                this.dgUnidades.DataSource = table;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                return;
            }
        }

        private void cboActividades_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar == 13)
            {
            }
        }

        private void cboBuscar2_Click(object sender, EventArgs e)
        {
            if (this.cboCampos.SelectedIndex > -1)
            {
                this.Traer_X_Campo();
                if (this.clientes != null)
                {
                    if (this.clientes.Count > 0)
                    {
                        this._indexCliente = 0;
                        this.Cargar_Cliente();
                        this.BindingNavigatorMoveFirstItem.PerformClick();
                        this.cmdModificar.Enabled = true;
                        this.cmdEliminar.Enabled = true;
                    }
                    else
                    {
                        this.Limpiar_Cliente();
                    }
                }
                else
                {
                    this.Limpiar_Cliente();
                }
            }
        }

        private void cboCategorias_Validated(object sender, EventArgs e)
        {
            if ((this.cboCategorias.Text.Trim() != string.Empty) && (this.cboCategorias.SelectedIndex == -1))
            {
                MessageBox.Show("El nombre de la categor\x00eda no existe", "Campo inexistente", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.cboCategorias.Text = string.Empty;
            }
        }

        private void cboFacturar_Validated(object sender, EventArgs e)
        {
            if ((this.cboFacturarA.Text.Trim() != string.Empty) && (this.cboFacturarA.SelectedIndex == -1))
            {
                MessageBox.Show("El nombre a facturar no existe", "Campo inexistente", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.cboFacturarA.Text = string.Empty;
            }
        }

        private void cboFiscal_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar == 13)
            {
            }
        }

        private void cboFiscal_Validated(object sender, EventArgs e)
        {
            if ((this.cboFiscalA.Text.Trim() != string.Empty) && (this.cboFiscalA.SelectedIndex == -1))
            {
                MessageBox.Show("la situaci\x00f3n fiscal no existe", "Campo inexistente", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.cboFiscalA.Text = string.Empty;
            }
        }

        private void chkItalic_CheckedChanged(object sender, EventArgs e)
        {
            if (!this._cambio)
            {
                this.Modificar_Texto();
            }
            this.txtHistorial.Focus();
        }

        private void chkNegrita_CheckedChanged(object sender, EventArgs e)
        {
            if (!this._cambio)
            {
                this.Modificar_Texto();
            }
            this.txtHistorial.Focus();
        }

        private void chkSubrayado_CheckedChanged(object sender, EventArgs e)
        {
            if (!this._cambio)
            {
                this.Modificar_Texto();
            }
            this.txtHistorial.Focus();
        }

        private void chkTachado_CheckedChanged(object sender, EventArgs e)
        {
            if (!this._cambio)
            {
                this.Modificar_Texto();
            }
            this.txtHistorial.Focus();
        }

        private void cmdAddArch_Click(object sender, EventArgs e)
        {
            if (this.ofd1.ShowDialog() == DialogResult.OK)
            {
                string[] fileNames = this.ofd1.FileNames;
                bool flag = false;
                int num3 = fileNames.Length - 1;
                for (int i = 0; i <= num3; i++)
                {
                    flag = false;
                    int num4 = this.lvArchivos.Items.Count - 1;
                    for (int j = 0; j <= num4; j++)
                    {
                        if (this.lvArchivos.Items[j].Name.ToUpper() == this.ofd1.SafeFileNames[i].ToUpper())
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        ListViewItem item = new ListViewItem();
                        this.listaArchs.Add(this.ofd1.FileNames[i]);
                        this.listaArchsN.Add(this.ofd1.FileNames[i]);
                        string str = this.ofd1.SafeFileNames[i].Substring(this.ofd1.SafeFileNames[i].LastIndexOf(".") + 1).ToUpper();
                        switch (str)
                        {
                            case "JPG":
                            case "JPEG":
                            case "GIF":
                            case "PNG":
                                item.ImageIndex = 0;
                                break;

                            default:
                                if ((str == "XLS") || (str == "XLSX"))
                                {
                                    item.ImageIndex = 1;
                                }
                                else if (((str == "DOC") || (str == "DOCX")) || (str == "RTF"))
                                {
                                    item.ImageIndex = 2;
                                }
                                else if ((str == "ZIP") || (str == "RAR"))
                                {
                                    item.ImageIndex = 3;
                                }
                                else
                                {
                                    item.ImageIndex = 4;
                                }
                                break;
                        }
                        item.Name = this.ofd1.SafeFileNames[i];
                        item.Text = this.ofd1.SafeFileNames[i];
                        this.lvArchivos.Items.Add(item);
                        continue;
                    }
                    MessageBox.Show("El archivo " + this.ofd1.SafeFileNames[i] + " ya existe", "Archivo existente", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }

        private void cmdAgAlarma_Click(object sender, EventArgs e)
        {
            frmAlarmas alarmas = new frmAlarmas();
            alarmas.Cli_ID = this.clientes[this._indexCliente].cli_ID;
            alarmas.Alarma = this.txtHistorial.SelectedText;
            alarmas.ShowDialog();
        }

        private void cmdBuscar3_Click(object sender, EventArgs e)
        {
            if (this.cboCategorias2.SelectedIndex > -1)
            {
                this.Traer_X_Categoria();
                if (this.clientes != null)
                {
                    if (this.clientes.Count > 0)
                    {
                        this._indexCliente = 0;
                        this.Cargar_Cliente();
                        this.BindingNavigatorMoveFirstItem.PerformClick();
                        this.cmdModificar.Enabled = true;
                        this.cmdEliminar.Enabled = true;
                    }
                    else
                    {
                        this.Limpiar_Cliente();
                    }
                }
                else
                {
                    this.Limpiar_Cliente();
                }
            }
        }

        private void cmdDelArch_Click(object sender, EventArgs e)
        {
            bool flag = false;
            int num2 = this.listaArchsN.Count - 1;
            int index = 0;
            while (index <= num2)
            {
                if (this.listaArchsN[index] == this.listaArchs[this.lvArchivos.SelectedItems[0].Index])
                {
                    flag = true;
                    break;
                }
                index++;
            }
            if (flag)
            {
                this.listaArchsN.RemoveAt(index);
            }
            else
            {
                this.listaArchsE.Add(this.listaArchs[this.lvArchivos.SelectedItems[0].Index]);
            }
            this.listaArchs.RemoveAt(this.lvArchivos.SelectedItems[0].Index);
            this.lvArchivos.Items.RemoveAt(this.lvArchivos.SelectedItems[0].Index);
            this.cmdDelArch.Enabled = false;
        }

        private void cmdEliminar_Click(object sender, EventArgs e)
        {
            this.panEliminar.Visible = true;
            this.cmdNo.Focus();
            this.cmdEliminar.Enabled = false;
            this.cmdGuardar.Enabled = false;
            this.cmdNuevo.Enabled = false;
            this.cmdModificar.Enabled = false;
            this.bnNavegador.Enabled = false;
            this.Habilitar_Pantalla(false);
            this.huboCambios = false;
        }

        private void cmdEliminarDir_Click(object sender, EventArgs e)
        {
            if ((MessageBox.Show("\x00bfDesea eliminar la direcci\x00f3n seleccionada?", "Eliminar direcci\x00f3n", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) && this.Eliminar_Direccion())
            {
                this.Limpiar_Direccion();
            }
        }

        private void cmdEliminarPer_Click(object sender, EventArgs e)
        {
            if ((MessageBox.Show("\x00bfDesea eliminar la persona seleccionada?", "Eliminar persona", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) && this.Eliminar_Persona())
            {
                this.Limpiar_Persona();
            }
        }

        private void cmdFuente_Click(object sender, EventArgs e)
        {
            if (this.FontDialog1.ShowDialog() == DialogResult.OK)
            {
                this.txtHistorial.SelectionFont = this.FontDialog1.Font;
                this.txtHistorial.SelectionColor = this.FontDialog1.Color;
            }
            this.txtHistorial.Focus();
        }

        private void cmdFuente2_Click(object sender, EventArgs e)
        {
            this.txtHistorial.SelectionFont = this.txtContacto1.Font;
            this.txtHistorial.SelectionColor = Color.Black;
            this.txtHistorial.Focus();
        }

        private void cmdGuardar_Click(object sender, EventArgs e)
        {
            this.Guardar();
        }

        private void cmdLimpiarDir_Click(object sender, EventArgs e)
        {
            this.Limpiar_Direccion();
        }

        private void cmdLimpiarPer_Click(object sender, EventArgs e)
        {
            this.Limpiar_Persona();
        }

        private void cmdModifDir_Click(object sender, EventArgs e)
        {
            this.Modificar_Direccion();
            this.Limpiar_Direccion();
        }

        private void cmdModificar_Click(object sender, EventArgs e)
        {
            this.huboCambios = true;
            this.botonMod = true;
            if (!this.txtEmpresa.ReadOnly)
            {
                this.Habilitar_Pantalla(false);
                this.cmdGuardar.Enabled = false;
                this.esModificacion = false;
                this.bnNavegador.Enabled = true;
            }
            else
            {
                this.Habilitar_Pantalla(true);
                this.cmdGuardar.Enabled = true;
                this.esModificacion = true;
                this.bnNavegador.Enabled = false;

                //AGREGADO AROTHAR
                this.txtHistorial.Text += "\n " + DateTime.Now.ToString("dd-MM-yyyy") + ":";
            }
        }

        private void cmdModifPer_Click(object sender, EventArgs e)
        {
            this.Modificar_Persona();
            this.Limpiar_Persona();
        }

        private void cmdNo_Click(object sender, EventArgs e)
        {
            this.panEliminar.Visible = false;
            this.cmdEliminar.Enabled = true;
            this.cmdGuardar.Enabled = false;
            this.cmdNuevo.Enabled = true;
            this.cmdModificar.Enabled = true;
            this.bnNavegador.Enabled = true;
        }

        private void cmdNuevo_Click(object sender, EventArgs e)
        {
            this.huboCambios = true;
            this.botonMod = false;
            this.esModificacion = false;
            this.Limpiar_Cliente();
            if (!this.txtEmpresa.ReadOnly)
            {
                this.Habilitar_Pantalla(false);
                this.cmdGuardar.Enabled = false;
                this.bnNavegador.Enabled = true;
            }
            else
            {
                this.Habilitar_Pantalla(true);
                this.cmdGuardar.Enabled = true;
                this.bnNavegador.Enabled = false;
            }
        }

        private void cmdNuevoDir_Click(object sender, EventArgs e)
        {
            this.Agregar_Direccion();
            this.Limpiar_Direccion();
        }

        private void cmdNuevoPer_Click(object sender, EventArgs e)
        {
            this.Agregar_Persona();
            this.Limpiar_Persona();
        }

        private void cmdSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmdSi_Click(object sender, EventArgs e)
        {
            this.Eliminar_Cliente();
            this.panEliminar.Visible = false;
            this.cmdEliminar.Enabled = true;
            this.cmdGuardar.Enabled = false;
            this.cmdNuevo.Enabled = true;
            this.cmdModificar.Enabled = true;
            this.bnNavegador.Enabled = true;
            this.Limpiar_Cliente();
        }

        private void cmdTodos_Click(object sender, EventArgs e)
        {
            this.Traer_Clientes();
            if ((this.clientes != null) && (this.clientes.Count > 0))
            {
                this.Cargar_Cliente();
                this.cmdModificar.Enabled = true;
                this.cmdEliminar.Enabled = true;
            }
        }

        private void cmdVerAlarma_Click(object sender, EventArgs e)
        {
            fmAlarmasCliente cliente = new fmAlarmasCliente();
            cliente.CliID = this.clientes[this._indexCliente].cli_ID;
            cliente.ShowDialog();
        }

        private void cmdVerTrab_Click(object sender, EventArgs e)
        {
            frmUni_X_Cliente cliente = new frmUni_X_Cliente();
            cliente.CliID = this.clientes[this._indexCliente].cli_ID;
            cliente.Show();
        }

        private void Crear_Cliente()
        {
            BerkoRules.Entities.Clientes row = new BerkoRules.Entities.Clientes();
            try
            {
                if (this.cboCategorias.SelectedIndex > -1)
                {
                    row.cli_Categoria = (byte)(this.cboCategorias.SelectedIndex + 1);
                }
                if (this.txtEmail.Text.Trim() != string.Empty)
                {
                    row.cli_Email = this.txtEmail.Text.Trim();
                }
                if (this.txtSitio.Text.Trim() != string.Empty)
                {
                    row.cli_SitioWeb = this.txtSitio.Text.Trim();
                }
                if (this.txtCuitA.Text.Trim() != string.Empty)
                {
                    row.cli_Cuit = this.txtCuitA.Text.Trim();
                }
                if (this.txtFiscalA.Text.Trim() != string.Empty)
                {
                    row.cli_Fiscal = this.txtFiscalA.Text.Trim();
                }
                if (this.txtDirFiscalA.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscal = this.txtDirFiscalA.Text.Trim();
                }
                if (this.txtLocaFiscalA.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscal = this.txtLocaFiscalA.Text.Trim();
                }
                if (this.cboFiscalA.SelectedIndex > -1)
                {
                    row.cli_SitFiscal = (byte)(this.cboFiscalA.SelectedIndex + 1);
                }
                if (this.cboFacturarA.SelectedIndex > -1)
                {
                    row.fac_ID = (byte)this.cboFacturarA.SelectedValue;
                }
                if (this.txtCuitB.Text.Trim() != string.Empty)
                {
                    row.cli_CuitB = this.txtCuitB.Text.Trim();
                }
                if (this.txtFiscalB.Text.Trim() != string.Empty)
                {
                    row.cli_FiscalB = this.txtFiscalB.Text.Trim();
                }
                if (this.txtDirFiscalB.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscalB = this.txtDirFiscalB.Text.Trim();
                }
                if (this.txtLocaFiscalB.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscalB = this.txtLocaFiscalB.Text.Trim();
                }
                if (this.cboFiscalB.SelectedIndex > -1)
                {
                    row.cli_SitFiscalB = (byte)(this.cboFiscalB.SelectedIndex + 1);
                }
                if (this.cboFacturarB.SelectedIndex > -1)
                {
                    row.fac_IDB = (byte)(this.cboFacturarB.SelectedValue);
                }
                if (this.txtCuitC.Text.Trim() != string.Empty)
                {
                    row.cli_CuitC = this.txtCuitC.Text.Trim();
                }
                if (this.txtFiscalC.Text.Trim() != string.Empty)
                {
                    row.cli_FiscalC = this.txtFiscalC.Text.Trim();
                }
                if (this.txtDirFiscalC.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscalC = this.txtDirFiscalC.Text.Trim();
                }
                if (this.txtLocaFiscalC.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscalC = this.txtLocaFiscalC.Text.Trim();
                }
                if (this.cboFiscalC.SelectedIndex > -1)
                {
                    row.cli_SitFiscalC = (byte)(this.cboFiscalC.SelectedIndex + 1);
                }
                if (this.cboFacturarC.SelectedIndex > -1)
                {
                    row.fac_IDC = (byte)(this.cboFacturarC.SelectedValue);
                }
                if (this.txtCuitD.Text.Trim() != string.Empty)
                {
                    row.cli_CuitD = this.txtCuitD.Text.Trim();
                }
                if (this.txtFiscalD.Text.Trim() != string.Empty)
                {
                    row.cli_FiscalD = this.txtFiscalD.Text.Trim();
                }
                if (this.txtDirFiscalD.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscalD = this.txtDirFiscalD.Text.Trim();
                }
                if (this.txtLocaFiscalD.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscalD = this.txtLocaFiscalD.Text.Trim();
                }
                if (this.cboFiscalD.SelectedIndex > -1)
                {
                    row.cli_SitFiscalD = (byte)(this.cboFiscalD.SelectedIndex + 1);
                }
                if (this.cboFacturarD.SelectedIndex > -1)
                {
                    row.fac_IDD = (byte)this.cboFacturarD.SelectedValue;
                }
                // row.cli_Seguir = this.chkSeguir.Checked;
                row.cli_Nombre = this.txtEmpresa.Text.Trim();
                row.cli_Observacion = this.txtObs.Text.Trim();
                row.cli_Actividad = this.txtActividad.Text.Trim();
                row.cli_FechaHora = DateTime.Now;
                row.cli_Historial = this.txtHistorial.Text;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                MessageBox.Show("No se pudo guardar el cliente. Reintente por favor...\r\nError: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            try
            {
                ClientesMapper.Instance().Insert(row);
            }
            catch (Exception exception7)
            {
                Exception exception2 = exception7;
                MessageBox.Show("No se pudo guardar el cliente. Reintente por favor...\r\nError: " + exception2.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            try
            {
                StreamWriter writer = new StreamWriter(ConfigurationManager.AppSettings["textosCli"] + row.cli_ID.ToString() + ".rtf");
                writer.Write(this.txtHistorial.Rtf);
                writer.Close();
                this._cambio = true;
                this.chkItalic.Checked = false;
                this.chkNegrita.Checked = false;
                this.chkSubrayado.Checked = false;
                this.chkTachado.Checked = false;
            }
            catch (Exception exception8)
            {
                Exception exception3 = exception8;
            }
            if (this.lvArchivos.Items.Count > 0)
            {
                string path = ConfigurationManager.AppSettings["archivos"] + row.cli_ID.ToString();
                Directory.CreateDirectory(path);
                int num5 = this.lvArchivos.Items.Count - 1;
                for (int i = 0; i <= num5; i++)
                {
                    Cliente_ArchivosObject obj3 = new Cliente_ArchivosObject();
                    obj3.cli_Arch = this.listaArchs[i].Substring(this.listaArchs[i].LastIndexOf(@"\") + 1).ToUpper();
                    obj3.cli_ID = row.cli_ID;
                    obj3.cli_Lenght = 0;
                    try
                    {
                        File.Copy(this.listaArchs[i], path + @"\" + obj3.cli_Arch.ToUpper());
                        Cliente_ArchivosMapper.Instance().Insert(obj3);
                    }
                    catch (Exception exception9)
                    {
                        Exception exception4 = exception9;
                    }
                }
            }
            if (this.gvDirecciones.Rows.Count > 0)
            {
                bool flag = false;
                BerkoRules.Entities.Clientes_Direcciones obj4 = null;
                int num6 = this.gvDirecciones.Rows.Count - 1;
                for (int j = 0; j <= num6; j++)
                {
                    obj4 = new BerkoRules.Entities.Clientes_Direcciones();
                    flag = false;
                    if (this.gvDirecciones.Rows[j].Cells["cdi_Direccion"].Value != null)
                    {
                        flag = true;
                        obj4.cdi_Direccion = this.gvDirecciones.Rows[j].Cells["cdi_Direccion"].Value.ToString();
                    }
                    else
                    {
                        obj4.cdi_Direccion = "";
                    }
                    if (this.gvDirecciones.Rows[j].Cells["cdi_Localidad"].Value != null)
                    {
                        flag = true;
                        obj4.cdi_Localidad = this.gvDirecciones.Rows[j].Cells["cdi_Localidad"].Value.ToString();
                    }
                    else
                    {
                        obj4.cdi_Localidad = "";
                    }
                    if (this.gvDirecciones.Rows[j].Cells["cdi_CodPostal"].Value != null)
                    {
                        flag = true;
                        obj4.cdi_CodPostal = this.gvDirecciones.Rows[j].Cells["cdi_CodPostal"].Value.ToString();
                    }
                    else
                    {
                        obj4.cdi_CodPostal = "";
                    }
                    if (this.gvDirecciones.Rows[j].Cells["cdi_Tel1"].Value != null)
                    {
                        flag = true;
                        obj4.cdi_Tel1 = this.gvDirecciones.Rows[j].Cells["cdi_Tel1"].Value.ToString();
                    }
                    else
                    {
                        obj4.cdi_Tel1 = "";
                    }
                    if (this.gvDirecciones.Rows[j].Cells["cdi_Tel2"].Value != null)
                    {
                        flag = true;
                        obj4.cdi_Tel2 = this.gvDirecciones.Rows[j].Cells["cdi_Tel2"].Value.ToString();
                    }
                    else
                    {
                        obj4.cdi_Tel2 = "";
                    }
                    if (this.gvDirecciones.Rows[j].Cells["cdi_Observacion"].Value != null)
                    {
                        flag = true;
                        obj4.cdi_Observacion = this.gvDirecciones.Rows[j].Cells["cdi_Observacion"].Value.ToString();
                    }
                    else
                    {
                        obj4.cdi_Observacion = "";
                    }
                    obj4.cli_ID = row.cli_ID;
                    if (flag)
                    {
                        try
                        {
                            Clientes_DireccionesMapper.Instance().Insert(obj4);
                        }
                        catch (Exception exception10)
                        {
                            Exception exception5 = exception10;
                            MessageBox.Show("No se pudo guardar la direcci\x00f3n. Reintente por favor...\r\nError: " + exception5.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            return;
                        }
                    }
                }
            }
            if (this.gvPersonas.Rows.Count > 0)
            {
                BerkoRules.Entities.Clientes_Personas obj5 = null;
                bool flag2 = false;
                int num7 = this.gvPersonas.Rows.Count - 1;
                for (int k = 0; k <= num7; k++)
                {
                    obj5 = new BerkoRules.Entities.Clientes_Personas();
                    flag2 = false;
                    if (this.gvPersonas.Rows[k].Cells["cpe_Nombres"].Value != null)
                    {
                        flag2 = true;
                        obj5.cpe_Nombres = this.gvPersonas.Rows[k].Cells["cpe_Nombres"].Value.ToString();
                    }
                    else
                    {
                        obj5.cpe_Nombres = "";
                    }
                    if (this.gvPersonas.Rows[k].Cells["cpe_Puesto"].Value != null)
                    {
                        flag2 = true;
                        obj5.cpe_Puesto = this.gvPersonas.Rows[k].Cells["cpe_Puesto"].Value.ToString();
                    }
                    else
                    {
                        obj5.cpe_Puesto = "";
                    }
                    if (this.gvPersonas.Rows[k].Cells["cpe_Email"].Value != null)
                    {
                        flag2 = true;
                        obj5.cpe_Email = this.gvPersonas.Rows[k].Cells["cpe_Email"].Value.ToString();
                    }
                    else
                    {
                        obj5.cpe_Email = "";
                    }
                    if (this.gvPersonas.Rows[k].Cells["cpe_Tel1"].Value != null)
                    {
                        flag2 = true;
                        obj5.cpe_Tel1 = this.gvPersonas.Rows[k].Cells["cpe_Tel1"].Value.ToString();
                    }
                    else
                    {
                        obj5.cpe_Tel1 = "";
                    }
                    if (this.gvPersonas.Rows[k].Cells["cpe_Tel2"].Value != null)
                    {
                        flag2 = true;
                        obj5.cpe_Tel2 = this.gvPersonas.Rows[k].Cells["cpe_Tel2"].Value.ToString();
                    }
                    else
                    {
                        obj5.cpe_Tel2 = "";
                    }
                    if (Information.IsDate((this.gvPersonas.Rows[k].Cells["cpe_FechaNac"].Value)))
                    {
                        flag2 = true;
                        obj5.cpe_FechaNac = (DateTime)this.gvPersonas.Rows[k].Cells["cpe_FechaNac"].Value;
                    }
                    obj5.cli_ID = row.cli_ID;
                    if (flag2)
                    {
                        try
                        {
                            Clientes_PersonasMapper.Instance().Insert(obj5);
                        }
                        catch (Exception exception11)
                        {
                            Exception exception6 = exception11;
                            MessageBox.Show("No se pudo guardar la direcci\x00f3n. Reintente por favor...\r\nError: " + exception6.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            return;
                        }
                    }
                }
            }
            MessageBox.Show("El cliente se guard\x00f3 correctamente", "OK", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }


        private void Eliminar_Cliente()
        {
            try
            {
                ClientesMapper.Instance().Delete(this.clientes[this._indexCliente].cli_ID);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                MessageBox.Show("No se pudo eliminar el cliente. Aseg\x00farese de que el cliente no haya sido usado", "Eliminar cliente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            this.Traer_Clientes();
            this.BindingSource1.MoveFirst();
            this.cmdGuardar.Enabled = false;
            this.cmdModificar.Enabled = true;
            this.cmdNuevo.Enabled = true;
            this.cmdEliminar.Enabled = false;
            this._indexCliente = 0;
            if ((this.clientes != null) && (this.clientes.Count > 0))
            {
                this.Cargar_Cliente();
                this.cmdModificar.Enabled = true;
                this.cmdEliminar.Enabled = true;
            }
        }

        private bool Eliminar_Direccion()
        {
            if (this.direcciones[this.gvDirecciones.CurrentRow.Index].cdi_ID > 0)
            {
                try
                {
                    Clientes_DireccionesMapper.Instance().Delete(this.direcciones[this.gvDirecciones.CurrentRow.Index].cdi_ID);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    MessageBox.Show("No se pudo eliminar la direcci\x00f3n seleccionada. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    bool flag = false;
                    return flag;
                }
            }
            this.direcciones.RemoveAt(this.gvDirecciones.CurrentRow.Index);
            this.gvDirecciones.DataSource = null;
            this.gvDirecciones.DataSource = this.direcciones;
            return true;
        }

        private bool Eliminar_Persona()
        {
            if (this.personas[this.gvPersonas.CurrentRow.Index].cpe_ID > 0)
            {
                try
                {
                    Clientes_PersonasMapper.Instance().Delete(this.personas[this.gvPersonas.CurrentRow.Index].cpe_ID);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    MessageBox.Show("No se pudo eliminar la persona seleccionada. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    bool flag = false;
                    return flag;
                }
            }
            this.personas.RemoveAt(this.gvPersonas.CurrentRow.Index);
            this.gvPersonas.DataSource = null;
            this.gvPersonas.DataSource = this.personas;
            return true;
        }

        private void frmClientes_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.huboCambios)
            {
                this.Guardar();
            }
        }

        private void frmClientes_Load(object sender, EventArgs e)
        {
            this.Traer_Facturar();
            if (_cargarTodos)
                this.Traer_Clientes();
            this.cmdGuardar.Enabled = false;
            this.cmdModificar.Enabled = true;
            this.cmdNuevo.Enabled = true;
            this.cmdEliminar.Enabled = false;
            if ((this.clientes != null) && (this.clientes.Count > 0))
            {
                this.Cargar_Cliente();
                this.cmdEliminar.Enabled = true;
            }
            this.Habilitar_Pantalla(false);
            this.cboCampos.SelectedIndex = 0;
        }

        private void Guardar()
        {
            if ((MessageBox.Show("\x00bfDese guardar los _cambios realizados?", "Guardar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) && this.Validar_Cliente())
            {
                this.Guardar_Cliente();
            }
            this.huboCambios = false;
            this.botonMod = false;
            this.cmdGuardar.Enabled = false;
            this.Habilitar_Pantalla(false);


            this.gvPersonas.CurrentCell = null;

            if (this.gvPersonas.Rows.Count > 1)
                this.gvPersonas.Rows[0].Visible = false;
            if (this.gvPersonas.Rows.Count > 2)
                this.gvPersonas.Rows[1].Visible = false;

            this.bnNavegador.Enabled = true;
        }

        private void Guardar_Cliente()
        {
            if (this.esModificacion)
            {
                this.Modificar_Cliente();
            }
            else if (this.botonMod)
            {
                this.Modificar_Cliente();
            }
            else
            {
                this.Crear_Cliente();
                this.Traer_Clientes();
                this._indexCliente = this.clientes.Count - 1;
                this.BindingSource1.MoveLast();
            }
        }

        private void Guardar_Cliente2()
        {
            if (this.botonMod)
            {
                this.Modificar_Cliente();
            }
            else
            {
                this.Crear_Cliente();
                this.Traer_Clientes();
                this._indexCliente = this.clientes.Count - 1;
                this.BindingSource1.MoveLast();
            }
        }

        private void Guardar2()
        {
            if (MessageBox.Show("\x00bfDese guardar los _cambios realizados?", "Guardar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (this.Validar_Cliente())
                {
                    this.Guardar_Cliente2();
                    this.huboCambios = false;
                    this.botonMod = false;
                    this.cmdGuardar.Enabled = false;
                    this.Habilitar_Pantalla(false);
                }
            }
            else
            {
                this.huboCambios = false;
                this.botonMod = false;
            }
        }

        private void gvDirecciones_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.gvDirecciones.CurrentCell.RowIndex <= -1)
            {
            }
        }

        private void gvPersonas_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.gvPersonas.CurrentCell.RowIndex <= -1)
            {
            }
        }

        private void Habilitar_Pantalla(bool habilitar)
        {
            this.cmdAddArch.Enabled = habilitar;
            this.cmdDelArch.Enabled = habilitar;
            this.txtEmpresa.ReadOnly = !habilitar;
            this.txtObs.ReadOnly = !habilitar;
            this.txtEmail.ReadOnly = !habilitar;
            this.txtSitio.ReadOnly = !habilitar;
            this.txtActividad.ReadOnly = !habilitar;
            this.cboCategorias.Enabled = habilitar;
            this.txtFiscalA.ReadOnly = !habilitar;
            this.txtDirFiscalA.ReadOnly = !habilitar;
            this.txtLocaFiscalA.ReadOnly = !habilitar;
            this.txtCuitA.ReadOnly = !habilitar;
            this.cboFacturarA.Enabled = habilitar;
            this.cboFiscalA.Enabled = habilitar;
            this.txtFiscalB.ReadOnly = !habilitar;
            this.txtDirFiscalB.ReadOnly = !habilitar;
            this.txtLocaFiscalB.ReadOnly = !habilitar;
            this.txtCuitB.ReadOnly = !habilitar;
            this.cboFacturarB.Enabled = habilitar;
            this.cboFiscalB.Enabled = habilitar;
            this.txtFiscalC.ReadOnly = !habilitar;
            this.txtDirFiscalC.ReadOnly = !habilitar;
            this.txtLocaFiscalC.ReadOnly = !habilitar;
            this.txtCuitC.ReadOnly = !habilitar;
            this.cboFacturarC.Enabled = habilitar;
            this.cboFiscalC.Enabled = habilitar;
            this.txtFiscalD.ReadOnly = !habilitar;
            this.txtDirFiscalD.ReadOnly = !habilitar;
            this.txtLocaFiscalD.ReadOnly = !habilitar;
            this.txtCuitD.ReadOnly = !habilitar;
            this.cboFacturarD.Enabled = habilitar;
            this.cboFiscalD.Enabled = habilitar;
            this.gvPersonas.ReadOnly = !habilitar;

            if (this.gvPersonas.Rows.Count > 1 && habilitar)
            {
                this.gvPersonas.Rows[0].Visible = habilitar;
                this.gvPersonas.Rows[1].Visible = habilitar;
            }
            else if (this.gvPersonas.Rows.Count > 0 && habilitar)
            {
                this.gvPersonas.Rows[0].Visible = habilitar;
            }
            this.gvDirecciones.ReadOnly = !habilitar;
            this.txtHistorial.ReadOnly = !habilitar;
            this.panBotonera.Enabled = habilitar;
        }


        private void Limpiar_Cliente()
        {
            this.txtEmpresa.Text = string.Empty;
            this.txtObs.Text = string.Empty;
            this.txtEmail.Text = string.Empty;
            this.txtSitio.Text = string.Empty;
            this.txtHistorial.Text = string.Empty;
            this.txtContacto1.Text = string.Empty;
            this.txtContacto1A.Text = string.Empty;
            this.txtContacto1B.Text = string.Empty;
            this.txtContacto2.Text = string.Empty;
            this.txtContacto2A.Text = string.Empty;
            this.txtContacto2B.Text = string.Empty;
            this.cboCategorias.SelectedValue = -1;
            this.txtActividad.Text = string.Empty;
            this.txtCuitA.Text = string.Empty;
            this.cboFacturarA.SelectedValue = -1;
            this.cboFacturarA.Text = string.Empty;
            this.cboFiscalA.SelectedValue = -1;
            this.cboFiscalA.Text = string.Empty;
            this.txtFiscalA.Text = string.Empty;
            this.txtDirFiscalA.Text = string.Empty;
            this.txtLocaFiscalA.Text = string.Empty;
            this.tbA.Text = string.Empty;
            this.txtCuitB.Text = string.Empty;
            this.cboFacturarA.SelectedValue = -1;
            this.cboFacturarA.Text = string.Empty;
            this.cboFiscalA.SelectedValue = -1;
            this.cboFiscalA.Text = string.Empty;
            this.txtFiscalB.Text = string.Empty;
            this.txtDirFiscalB.Text = string.Empty;
            this.txtLocaFiscalB.Text = string.Empty;
            this.tbB.Text = string.Empty;
            this.txtCuitC.Text = string.Empty;
            this.cboFacturarA.SelectedValue = -1;
            this.cboFacturarA.Text = string.Empty;
            this.cboFiscalA.SelectedValue = -1;
            this.cboFiscalA.Text = string.Empty;
            this.txtFiscalC.Text = string.Empty;
            this.txtDirFiscalC.Text = string.Empty;
            this.txtLocaFiscalC.Text = string.Empty;
            this.tbC.Text = "";
            this.txtCuitD.Text = string.Empty;
            this.cboFacturarA.SelectedValue = -1;
            this.cboFacturarA.Text = string.Empty;
            this.cboFiscalA.SelectedValue = -1;
            this.cboFiscalA.Text = string.Empty;
            this.txtFiscalD.Text = string.Empty;
            this.txtDirFiscalD.Text = string.Empty;
            this.txtLocaFiscalD.Text = string.Empty;
            this.tbD.Text = string.Empty;
            this.direcciones = null;
            this.personas = null;
            this.gvDirecciones.DataSource = this.direcciones;
            this.gvPersonas.DataSource = this.personas;
            this.dgUnidades.DataSource = null;
            this.lvArchivos.Items.Clear();
            this.txtEmpresa.Focus();
        }

        private void Limpiar_Direccion()
        {
        }

        private void Limpiar_Persona()
        {
        }

        private void lnkFacturar_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frmFacturar facturar = new frmFacturar();
            if (facturar.ShowDialog() != DialogResult.Cancel)
            {
                this.Traer_Facturar();
            }
        }

        private void lvArchivos_Click(object sender, EventArgs e)
        {
            if (!this.txtEmpresa.ReadOnly)
            {
                if (this.lvArchivos.SelectedItems != null)
                {
                    if (this.lvArchivos.SelectedItems.Count > 0)
                    {
                        this.cmdDelArch.Enabled = true;
                    }
                    else
                    {
                        this.cmdDelArch.Enabled = false;
                    }
                }
                else
                {
                    this.cmdDelArch.Enabled = false;
                }
            }
        }

        private void lvArchivos_DoubleClick(object sender, EventArgs e)
        {
            if ((this.lvArchivos.SelectedItems != null) && (this.lvArchivos.SelectedItems.Count > 0))
            {
                try
                {
                    //todo: implementar Process no se que iria, por eso no lo hago ahora.
                    //Process.Start(this.listaArchs[this.lvArchivos.SelectedItems[0].Index]);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                }
            }
        }

        private void Modificar_Cliente()
        {
            int num;
            BerkoRules.Entities.Clientes row = new BerkoRules.Entities.Clientes(this.clientes[this._indexCliente].cli_ID);
            try
            {
                //row.Cli_ID2 = this.clientes[this._indexCliente].cli_ID;
                if (this.cboCategorias.SelectedIndex > -1)
                {
                    row.cli_Categoria = (byte)(this.cboCategorias.SelectedIndex + 1);
                }
                this.clientes[this._indexCliente].cli_Categoria = row.cli_Categoria;
                if (this.txtEmail.Text.Trim() != string.Empty)
                {
                    row.cli_Email = this.txtEmail.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_Email = row.cli_Email;
                if (this.txtSitio.Text.Trim() != string.Empty)
                {
                    row.cli_SitioWeb = this.txtSitio.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_SitioWeb = row.cli_SitioWeb;
                if (this.txtCuitA.Text.Trim() != string.Empty)
                {
                    row.cli_Cuit = this.txtCuitA.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_Cuit = row.cli_Cuit;
                if (this.txtFiscalA.Text.Trim() != string.Empty)
                {
                    row.cli_Fiscal = this.txtFiscalA.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_Fiscal = row.cli_Fiscal;
                if (this.txtDirFiscalA.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscal = this.txtDirFiscalA.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_DirFiscal = row.cli_DirFiscal;
                if (this.txtLocaFiscalA.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscal = this.txtLocaFiscalA.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_LocalidadFiscal = row.cli_LocalidadFiscal;
                if (this.cboFiscalA.SelectedIndex > -1)
                {
                    row.cli_SitFiscal = (byte)(this.cboFiscalA.SelectedIndex + 1);
                    this.clientes[this._indexCliente].cli_SitFiscal = row.cli_SitFiscal;
                }
                if (this.cboFacturarA.SelectedIndex > -1)
                {
                    row.fac_ID = (byte)this.cboFacturarA.SelectedValue;
                    this.clientes[this._indexCliente].fac_ID = row.fac_ID;
                }
                if (this.txtCuitB.Text.Trim() != string.Empty)
                {
                    row.cli_CuitB = this.txtCuitB.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_CuitB = row.cli_CuitB;
                if (this.txtFiscalB.Text.Trim() != string.Empty)
                {
                    row.cli_FiscalB = this.txtFiscalB.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_FiscalB = row.cli_FiscalB;
                if (this.txtDirFiscalB.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscalB = this.txtDirFiscalB.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_DirFiscalB = row.cli_DirFiscalB;
                if (this.txtLocaFiscalB.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscalB = this.txtLocaFiscalB.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_LocalidadFiscalB = row.cli_LocalidadFiscalB;
                if (this.cboFiscalB.SelectedIndex > -1)
                {
                    row.cli_SitFiscalB = (byte)(this.cboFiscalB.SelectedIndex + 1);
                    this.clientes[this._indexCliente].cli_SitFiscalB = row.cli_SitFiscalB;
                }
                if (this.cboFacturarB.SelectedIndex > -1)
                {
                    row.fac_IDB = (byte)this.cboFacturarB.SelectedValue;
                    this.clientes[this._indexCliente].fac_IDB = row.fac_IDB;
                }
                if (this.txtCuitC.Text.Trim() != string.Empty)
                {
                    row.cli_CuitC = this.txtCuitC.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_CuitC = row.cli_CuitC;
                if (this.txtFiscalC.Text.Trim() != string.Empty)
                {
                    row.cli_FiscalC = this.txtFiscalC.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_FiscalC = row.cli_FiscalC;
                if (this.txtDirFiscalC.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscalC = this.txtDirFiscalC.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_DirFiscalC = row.cli_DirFiscalC;
                if (this.txtLocaFiscalC.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscalC = this.txtLocaFiscalC.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_LocalidadFiscalC = row.cli_LocalidadFiscalC;
                if (this.cboFiscalC.SelectedIndex > -1)
                {
                    row.cli_SitFiscalC = (byte)(this.cboFiscalC.SelectedIndex + 1);
                    this.clientes[this._indexCliente].cli_SitFiscalC = row.cli_SitFiscalC;
                }
                if (this.cboFacturarC.SelectedIndex > -1)
                {
                    row.fac_IDC = (byte)this.cboFacturarC.SelectedValue;
                    this.clientes[this._indexCliente].fac_IDC = row.fac_IDC;
                }
                if (this.txtCuitD.Text.Trim() != string.Empty)
                {
                    row.cli_CuitD = this.txtCuitD.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_CuitD = row.cli_CuitD;
                if (this.txtFiscalD.Text.Trim() != string.Empty)
                {
                    row.cli_FiscalD = this.txtFiscalD.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_FiscalD = row.cli_FiscalD;
                if (this.txtDirFiscalD.Text.Trim() != string.Empty)
                {
                    row.cli_DirFiscalD = this.txtDirFiscalD.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_DirFiscalD = row.cli_DirFiscalD;
                if (this.txtLocaFiscalD.Text.Trim() != string.Empty)
                {
                    row.cli_LocalidadFiscalD = this.txtLocaFiscalD.Text.Trim();
                }
                this.clientes[this._indexCliente].cli_LocalidadFiscalD = row.cli_LocalidadFiscalD;
                if (this.cboFiscalD.SelectedIndex > -1)
                {
                    row.cli_SitFiscalD = (byte)(this.cboFiscalD.SelectedIndex + 1);
                    this.clientes[this._indexCliente].cli_SitFiscalD = row.cli_SitFiscalD;
                }
                if (this.cboFacturarD.SelectedIndex > -1)
                {
                    row.fac_IDD = (byte)this.cboFacturarD.SelectedValue;
                    this.clientes[this._indexCliente].fac_IDD = row.fac_IDD;
                }

                row.cli_Seguir = chkSeguir.Checked;

                row.cli_Nombre = this.txtEmpresa.Text.Trim();
                this.clientes[this._indexCliente].cli_Nombre = row.cli_Nombre;
                row.cli_Observacion = this.txtObs.Text.Trim();
                this.clientes[this._indexCliente].cli_Observacion = row.cli_Observacion;
                row.cli_Actividad = this.txtActividad.Text.Trim();
                this.clientes[this._indexCliente].cli_Actividad = row.cli_Actividad;
                row.cli_Historial = this.txtHistorial.Text;
                this.clientes[this._indexCliente].cli_Historial = row.cli_Historial;
                row.cli_FechaHora = DateTime.Now;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                MessageBox.Show("No se pudo guardar el cliente. Reintente por favor...\r\nError: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            try
            {
                StreamWriter writer = new StreamWriter(ConfigurationManager.AppSettings["textosCli"] + row.cli_ID.ToString() + ".rtf");
                writer.Write(this.txtHistorial.Rtf);
                writer.Close();
                this._cambio = true;
                this.chkItalic.Checked = false;
                this.chkNegrita.Checked = false;
                this.chkSubrayado.Checked = false;
                this.chkTachado.Checked = false;
            }
            catch (Exception exception10)
            {
                Exception exception2 = exception10;
            }
            try
            {
                ClientesMapper.Instance().Save(row);
                Clientes_DireccionesMapper.Instance().DeleteByClientes(row.cli_ID);
                Clientes_PersonasMapper.Instance().DeleteByClientes(row.cli_ID);
            }
            catch (Exception exception11)
            {
                Exception exception3 = exception11;
                MessageBox.Show("No se pudo actualizar el cliente seleccionado. Reintente por favor...\r\nError: " + exception3.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            string path = ConfigurationManager.AppSettings["archivos"] + row.cli_ID.ToString();
            int num3 = this.listaArchsE.Count - 1;
            for (num = 0; num <= num3; num++)
            {
                try
                {
                    File.Delete(this.listaArchsE[num]);
                }
                catch (Exception exception12)
                {
                    Exception exception4 = exception12;
                }
            }
            try
            {
                Cliente_ArchivosMapper.Instance().DeleteByClientes(row.cli_ID);
            }
            catch (Exception exception13)
            {
                Exception exception5 = exception13;
            }
            if (this.lvArchivos.Items.Count > 0)
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                int num4 = this.listaArchsN.Count - 1;
                for (num = 0; num <= num4; num++)
                {
                    try
                    {
                        File.Copy(this.listaArchsN[num], path + @"\" + this.listaArchsN[num].Substring(this.listaArchsN[num].LastIndexOf(@"\") + 1).ToUpper());
                    }
                    catch (Exception exception14)
                    {
                        Exception exception6 = exception14;
                    }
                }
                int num5 = this.lvArchivos.Items.Count - 1;
                for (num = 0; num <= num5; num++)
                {
                    Cliente_ArchivosObject obj3 = new Cliente_ArchivosObject();
                    obj3.cli_Arch = this.listaArchs[num].Substring(this.listaArchs[num].LastIndexOf(@"\") + 1).ToUpper();
                    obj3.cli_ID = row.cli_ID;
                    obj3.cli_Lenght = 0;
                    try
                    {
                        Cliente_ArchivosMapper.Instance().Insert(obj3);
                    }
                    catch (Exception exception15)
                    {
                        Exception exception7 = exception15;
                    }
                }
            }
            if (this.direcciones != null)
            {
                int num6 = this.direcciones.Count - 1;
                for (num = 0; num <= num6; num++)
                {
                    this.direcciones[num].cli_ID = row.cli_ID;
                    try
                    {
                        if (this.direcciones[num].cdi_Direccion == null)
                        {
                            this.direcciones[num].cdi_Direccion = "";
                        }
                        if (this.direcciones[num].cdi_Localidad == null)
                        {
                            this.direcciones[num].cdi_Localidad = "";
                        }
                        if (this.direcciones[num].cdi_CodPostal == null)
                        {
                            this.direcciones[num].cdi_CodPostal = "";
                        }
                        if (this.direcciones[num].cdi_Tel1 == null)
                        {
                            this.direcciones[num].cdi_Tel1 = "";
                        }
                        if (this.direcciones[num].cdi_Tel2 == null)
                        {
                            this.direcciones[num].cdi_Tel2 = "";
                        }
                        if (this.direcciones[num].cdi_Observacion == null)
                        {
                            this.direcciones[num].cdi_Observacion = "";
                        }
                        Clientes_DireccionesMapper.Instance().Insert(this.direcciones[num]);
                    }
                    catch (Exception exception16)
                    {
                        ProjectData.SetProjectError(exception16);
                        Exception exception8 = exception16;
                        ProjectData.ClearProjectError();
                    }
                }
            }
            if (this.personas != null)
            {
                int num7 = this.personas.Count - 1;
                for (num = 0; num <= num7; num++)
                {
                    this.personas[num].cli_ID = row.cli_ID;
                    try
                    {
                        if (this.personas[num].cpe_Nombres == null)
                        {
                            this.personas[num].cpe_Nombres = "";
                        }
                        if (this.personas[num].cpe_Apellido == null)
                        {
                            this.personas[num].cpe_Apellido = "";
                        }
                        if (this.personas[num].cpe_Puesto == null)
                        {
                            this.personas[num].cpe_Puesto = "";
                        }
                        if (this.personas[num].cpe_Tel1 == null)
                        {
                            this.personas[num].cpe_Tel1 = "";
                        }
                        if (this.personas[num].cpe_Tel2 == null)
                        {
                            this.personas[num].cpe_Tel2 = "";
                        }
                        if (this.personas[num].cpe_Email == null)
                        {
                            this.personas[num].cpe_Email = "";
                        }
                        Clientes_PersonasMapper.Instance().Insert(this.personas[num]);
                    }
                    catch (Exception exception17)
                    {
                        ProjectData.SetProjectError(exception17);
                        Exception exception9 = exception17;
                        ProjectData.ClearProjectError();
                    }
                }
            }
            MessageBox.Show("Los cambios se guardaron correctamente", "OK", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }

        private void Modificar_Direccion()
        {
            this.gvDirecciones.DataSource = null;
            this.gvDirecciones.DataSource = this.direcciones;
        }

        private void Modificar_Persona()
        {
            this.gvPersonas.DataSource = null;
            this.gvPersonas.DataSource = this.personas;
        }

        private void Modificar_Texto()
        {
            if (this.chkNegrita.Checked)
            {
                if (this.chkSubrayado.Checked)
                {
                    if (this.chkTachado.Checked)
                    {
                        if (this.chkItalic.Checked)
                        {
                            this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout | FontStyle.Underline | FontStyle.Italic | FontStyle.Bold);
                        }
                        else
                        {
                            this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout | FontStyle.Underline | FontStyle.Bold);
                        }
                    }
                    else if (this.chkItalic.Checked)
                    {
                        this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Underline | FontStyle.Italic | FontStyle.Bold);
                    }
                    else
                    {
                        this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Underline | FontStyle.Bold);
                    }
                }
                else if (this.chkTachado.Checked)
                {
                    if (this.chkItalic.Checked)
                    {
                        this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout | FontStyle.Italic | FontStyle.Bold);
                    }
                    else
                    {
                        this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout | FontStyle.Bold);
                    }
                }
                else if (this.chkItalic.Checked)
                {
                    this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Italic | FontStyle.Bold);
                }
                else
                {
                    this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Bold);
                }
            }
            else if (this.chkSubrayado.Checked)
            {
                if (this.chkTachado.Checked)
                {
                    if (this.chkItalic.Checked)
                    {
                        this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout | FontStyle.Underline | FontStyle.Italic);
                    }
                    else
                    {
                        this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout | FontStyle.Underline);
                    }
                }
                else if (this.chkItalic.Checked)
                {
                    this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Underline | FontStyle.Italic);
                }
                else
                {
                    this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Underline);
                }
            }
            else if (this.chkTachado.Checked)
            {
                if (this.chkItalic.Checked)
                {
                    this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout | FontStyle.Italic);
                }
                else
                {
                    this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Strikeout);
                }
            }
            else if (this.chkItalic.Checked)
            {
                this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Italic);
            }
            else
            {
                this.txtHistorial.SelectionFont = new Font(this.txtHistorial.SelectionFont, FontStyle.Regular);
            }
        }

        private void Traer_Clientes()
        {
            try
            {
                this.clientes = ClientesMapper.Instance().GetAll();
                this.BindingSource1.DataSource = this.clientes;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show("No se pudieron traer los clientes. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.clientes = null;
                ProjectData.ClearProjectError();
            }
        }

        private void Traer_Direcciones(int cliID)
        {
            try
            {
                this.direcciones = Clientes_DireccionesMapper.Instance().GetByClientes(cliID);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show("No se pudieron traer las direcciones del cliente seleccionado. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                ProjectData.ClearProjectError();
                return;
                ProjectData.ClearProjectError();
            }
            this.ClientesDireccionesObjectBindingSource.DataSource = null;
            this.ClientesDireccionesObjectBindingSource.DataSource = this.direcciones;
            this.gvDirecciones.DataSource = this.ClientesDireccionesObjectBindingSource;
        }

        private bool Traer_Facturar()
        {
            try
            {
                this.cboFacturarA.DataSource = FacturarMapper.Instance().GetAll();
                this.cboFacturarA.DisplayMember = "fac_Nombre";
                this.cboFacturarA.ValueMember = "fac_ID";
                this.cboFacturarB.DataSource = FacturarMapper.Instance().GetAll();
                this.cboFacturarB.DisplayMember = "fac_Nombre";
                this.cboFacturarB.ValueMember = "fac_ID";
                this.cboFacturarC.DataSource = FacturarMapper.Instance().GetAll();
                this.cboFacturarC.DisplayMember = "fac_Nombre";
                this.cboFacturarC.ValueMember = "fac_ID";
                this.cboFacturarD.DataSource = FacturarMapper.Instance().GetAll();
                this.cboFacturarD.DisplayMember = "fac_Nombre";
                this.cboFacturarD.ValueMember = "fac_ID";
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show("No se pudo traer la lista a quien facturar. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                bool flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return true;
        }

        private void Traer_Personas(int cliID)
        {
            try
            {
                this.personas = Clientes_PersonasMapper.Instance().GetByClientes(cliID);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show("No se pudieron traer las personas del cliente seleccionado. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                ProjectData.ClearProjectError();
                return;
            }
            this.txtContacto1.Text = "";
            this.txtContacto1A.Text = "";
            this.txtContacto1B.Text = "";
            this.txtContacto2.Text = "";
            this.txtContacto2A.Text = "";
            this.txtContacto2B.Text = "";

            if (this.personas != null)
            {
                if (this.personas.Count > 0)
                {
                    this.txtContacto1.Text = this.personas[0].cpe_Nombres;
                    this.txtContacto1A.Text = this.personas[0].cpe_Tel1;
                    this.txtContacto1B.Text = this.personas[0].cpe_Email;
                }
                if (this.personas.Count > 1)
                {
                    this.txtContacto2.Text = this.personas[1].cpe_Nombres;
                    this.txtContacto2A.Text = this.personas[1].cpe_Tel1;
                    this.txtContacto2B.Text = this.personas[1].cpe_Email;
                }
            }


            this.ClientesPersonasObjectBindingSource.DataSource = null;
            this.ClientesPersonasObjectBindingSource.DataSource = this.personas;
            this.gvPersonas.DataSource = this.ClientesPersonasObjectBindingSource;

            this.gvPersonas.CurrentCell = null;

            if (this.gvPersonas.Rows.Count > 1)
                this.gvPersonas.Rows[0].Visible = false;
            if (this.gvPersonas.Rows.Count > 2)
                this.gvPersonas.Rows[1].Visible = false;

            this.txtTexto.Focus();
        }

        private void Traer_X_Campo()
        {
            string str;
            byte num = 0;
            switch (this.cboCampos.SelectedIndex)
            {
                case 0:
                    str = "cli_Nombre";
                    num = 1;
                    break;

                case 1:
                    str = "todos";
                    num = 4;
                    break;

                case 2:
                    str = "cli_Referencia";
                    num = 1;
                    break;

                case 3:
                    str = "cli_Observacion";
                    num = 1;
                    break;

                case 4:
                    str = "cli_Email";
                    num = 1;
                    break;

                case 5:
                    str = "cli_SitioWeb";
                    num = 1;
                    break;

                case 6:
                    str = "cli_Historial";
                    num = 1;
                    break;

                case 7:
                    str = "cli_Fiscal";
                    num = 1;
                    break;

                case 8:
                    str = "cli_DirFiscal";
                    num = 1;
                    break;

                case 9:
                    str = "cli_LocalidadFiscal";
                    num = 1;
                    break;

                case 10:
                    str = "cli_Cuit";
                    num = 1;
                    break;

                case 11:
                    str = "cli_FiscalB";
                    num = 1;
                    break;

                case 12:
                    str = "cli_DirFiscalB";
                    num = 1;
                    break;

                case 13:
                    str = "cli_LocalidadFiscalB";
                    num = 1;
                    break;

                case 14:
                    str = "cli_CuitB";
                    num = 1;
                    break;

                case 15:
                    str = "cli_FiscalC";
                    num = 1;
                    break;

                case 0x10:
                    str = "cli_DirFiscalC";
                    num = 1;
                    break;

                case 0x11:
                    str = "cli_LocalidadFiscalC";
                    num = 1;
                    break;

                case 0x12:
                    str = "cli_CuitC";
                    num = 1;
                    break;

                case 0x13:
                    str = "cli_FiscalD";
                    num = 1;
                    break;

                case 20:
                    str = "cli_DirFiscalD";
                    num = 1;
                    break;

                case 0x15:
                    str = "cli_LocalidadFiscalD";
                    num = 1;
                    break;

                case 0x16:
                    str = "cli_CuitD";
                    num = 1;
                    break;

                case 0x17:
                    str = "cdi_Direccion";
                    num = 2;
                    break;

                case 0x18:
                    str = "cdi_Localidad";
                    num = 2;
                    break;

                case 0x19:
                    str = "cdi_Tel1";
                    num = 2;
                    break;

                case 0x1a:
                    str = "cdi_Tel2";
                    num = 2;
                    break;

                case 0x1b:
                    str = "cdi_CodPostal";
                    num = 2;
                    break;

                case 0x1c:
                    str = "cdi_Observacion";
                    num = 2;
                    break;

                case 0x1d:
                    str = "cpe_Nombres";
                    num = 3;
                    break;

                case 30:
                    str = "cpe_Apellido";
                    num = 3;
                    break;

                case 0x1f:
                    str = "cpe_Email";
                    num = 3;
                    break;

                case 0x20:
                    str = "cpe_Puesto";
                    num = 3;
                    break;

                case 0x21:
                    str = "cpe_Tel1";
                    num = 3;
                    break;

                case 0x22:
                    str = "cpe_Tel2";
                    num = 3;
                    break;

                default:
                    str = "";
                    break;
            }
            try
            {
                switch (((byte)(num - 1)))
                {
                    case 0:
                        this.clientes = ClientesMapper.Instance().Traer_X_Campo(str, this.txtTexto.Text.Trim());
                        break;

                    case 1:
                        this.clientes = ClientesMapper.Instance().Traer_X_Campo_Direccion(str, this.txtTexto.Text.Trim());
                        break;

                    case 2:
                        this.clientes = ClientesMapper.Instance().Traer_X_Campo_Persona(str, this.txtTexto.Text.Trim());
                        break;

                    case 3:
                        this.clientes = ClientesMapper.Instance().Traer_X_Todos_Campos(this.txtTexto.Text.Trim());
                        break;
                }
                this.BindingSource1.DataSource = this.clientes;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show("No se pudieron traer los clientes. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.clientes = null;
                ProjectData.ClearProjectError();
            }
        }

        private void Traer_X_Categoria()
        {
            try
            {
                this.clientes = ClientesMapper.Instance().Traer_X_Categoria((byte)(this.cboCategorias2.SelectedIndex + 1));
                this.BindingSource1.DataSource = this.clientes;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show("No se pudieron traer los clientes. Reintente por favor...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.clientes = null;
                ProjectData.ClearProjectError();
            }
        }

        private void txtApellido_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtCP_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtCuit_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.cboFacturarA.Focus();
            }
        }

        private void txtDireccion_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtEmail_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.txtSitio.Focus();
            }
        }

        private void txtEmailPer_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtEmpresa_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.txtFiscalA.Focus();
            }
        }

        private void txtFechaNac_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtFiscal_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.txtContacto1.Focus();
            }
        }

        private void txtHistorial_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((Strings.Asc(e.KeyChar) == 13) && (1 == this.txtHistorial.GetLineFromCharIndex(this.txtHistorial.GetFirstCharIndexOfCurrentLine()))) && (this.txtHistorial.GetFirstCharIndexOfCurrentLine() == 1))
            {
                if (this.txtHistorial.Rtf.Substring(0x6c, 3) == "par")
                {
                    this.txtHistorial.Rtf = this.txtHistorial.Rtf.Insert(12, @"ansicpg1252\");
                }
                this.txtHistorial.Rtf = this.txtHistorial.Rtf.Insert(0x77, " " + DateAndTime.Now.ToString("dd/MM/yyyy  HH:mm") + ":");
                this.txtHistorial.Select(0x12, 0);
            }
        }

        private void txtHistorial_SelectionChanged(object sender, EventArgs e)
        {
            this._cambio = true;
            if (this.txtHistorial.SelectionFont != null)
            {
                this.chkNegrita.Checked = this.txtHistorial.SelectionFont.Bold;
            }
            if (this.txtHistorial.SelectionFont != null)
            {
                this.chkSubrayado.Checked = this.txtHistorial.SelectionFont.Underline;
            }
            if (this.txtHistorial.SelectionFont != null)
            {
                this.chkTachado.Checked = this.txtHistorial.SelectionFont.Strikeout;
            }
            if (this.txtHistorial.SelectionFont != null)
            {
                this.chkItalic.Checked = this.txtHistorial.SelectionFont.Italic;
            }
            this._cambio = false;
        }

        private void txtLocalidad_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtNombre_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtObservacion_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.cboFiscalA.Focus();
            }
        }

        private void txtPuesto_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtRef_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.txtEmail.Focus();
            }
        }

        private void txtSitio_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.txtCuitA.Focus();
            }
        }

        private void txtTel1Dir_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtTel2Dir_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtTelPer1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtTelPer2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
            }
        }

        private void txtTexto_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Strings.Asc(e.KeyChar) == 13)
            {
                this.cboBuscar2.PerformClick();
            }
        }

        private bool Validar_Cliente()
        {
            if (this.txtEmpresa.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Debe ingresar un nombre v\x00e1lido para el cliente", "Campo vac\x00edo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            return true;
        }

        private void Verificar_Archivos()
        {
            ListViewItem item = null;
            Cliente_ArchivosObjectList byClientes;
            string str = ConfigurationManager.AppSettings["archivos"] + this.clientes[this._indexCliente].cli_ID.ToString() + @"\";
            try
            {
                byClientes = Cliente_ArchivosMapper.Instance().GetByClientes(this.clientes[this._indexCliente].cli_ID);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                ProjectData.ClearProjectError();
                return;
            }
            this.listaArchs = new List<string>();
            this.listaArchsN = new List<string>();
            this.listaArchsE = new List<string>();
            this.lvArchivos.Items.Clear();
            int num3 = byClientes.Count - 1;
            for (int i = 0; i <= num3; i++)
            {
                this.listaArchs.Add(str + byClientes[i].cli_Arch);
                item = new ListViewItem();
                string str2 = byClientes[i].cli_Arch.Substring(byClientes[i].cli_Arch.LastIndexOf(".") + 1).ToUpper();
                switch (str2)
                {
                    case "JPG":
                    case "JPEG":
                    case "GIF":
                    case "PNG":
                        item.ImageIndex = 0;
                        break;

                    default:
                        if ((str2 == "XLS") || (str2 == "XLSX"))
                        {
                            item.ImageIndex = 1;
                        }
                        else if (((str2 == "DOC") || (str2 == "DOCX")) || (str2 == "RTF"))
                        {
                            item.ImageIndex = 2;
                        }
                        else if ((str2 == "ZIP") || (str2 == "RAR"))
                        {
                            item.ImageIndex = 3;
                        }
                        else
                        {
                            item.ImageIndex = 4;
                        }
                        break;
                }
                item.ToolTipText = byClientes[i].cli_Arch.Substring(byClientes[i].cli_Arch.LastIndexOf(@"\") + 1).ToUpper();
                item.Name = byClientes[i].cli_Arch.Substring(byClientes[i].cli_Arch.LastIndexOf(@"\") + 1).ToUpper();
                item.Text = byClientes[i].cli_Arch.Substring(byClientes[i].cli_Arch.LastIndexOf(@"\") + 1).ToLower();
                this.lvArchivos.Items.Add(item);
            }
        }

        private void Verificar_Tiene_Alarmas()
        {
            try
            {
                if (AlarmasMapper.Instance().Cantidad_Alarmas(this.clientes[this._indexCliente].cli_ID) > 0)
                {
                    this.cmdVerAlarma.Enabled = true;
                }
                else
                {
                    this.cmdVerAlarma.Enabled = false;
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                ProjectData.ClearProjectError();
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        public void CargarDesdeID(int cli_ID)
        {
            this.clientes = new ClientesList();
            this.clientes.Add(ClientesMapper.Instance().GetOne(cli_ID));
            //this._trabajos = TrabajosMapper.Instance().GetOne(tra_ID);
            this.BindingSource1.DataSource = this.clientes;
            if (this.clientes != null)
            {
                int num2 = this.clientes.Count - 1;
                for (int i = 0; i <= num2; i++)
                {
                    if (this.clientes[i].cli_ID == cli_ID)
                    {
                        this._indexCliente = i;
                        this.BindingSource1.Position = i;
                        this.Cargar_Cliente();
                    }
                }
            }
        }
    }
}